package com.handu.luna.core.domain.promotion;

import com.handu.luna.core.domain.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.NoRepositoryBean;

import java.util.List;

/**
 * Created by wangzailiang on 2014/6/25.
 */
@NoRepositoryBean
public interface BonusRepository<T extends Bonus> extends JpaRepository<T,Long>, BaseRepository<T>,JpaSpecificationExecutor<T> {

    @Query("select c from #{#entityName} c where c.bonusPromotionId = ?1 order by c.createdDate desc")
    public Page<T> findAllByBonusPromotionId(Long bonusPromotionId, Pageable pageable);

    @Query("select c from #{#entityName} c where c.bonusPromotionId = ?1 order by c.createdDate desc")
    public List<T> findAllByBonusPromotionId(Long bonusPromotionId);

    @Modifying
    @Query("delete #{#entityName} c where c.bonusPromotionId = ?1")
    public void deleteByBonusPromotionId(Long bonusPromotionId);
}
